/*
 * 类名称:PersonInfoServiceImpl.java
 * 包名称:com.lht.admin.service.impl
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-12-29 14:10:09        ZhengZhanWu     初版做成
 */
package com.lht.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lht.admin.dao.PersonInfoDao;
import com.lht.admin.entity.PersonInfoEntity;
import com.lht.admin.service.PersonInfoService;
import com.lht.admin.utils.QueryPlus;
import com.lht.admin.utils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 借款人个人信息表Service实现类
 *
 * @author ZhengZhanWu
 * @date 2019-12-29 14:10:09
 */
@Service("personInfoService")
public class PersonInfoServiceImpl extends ServiceImpl<PersonInfoDao, PersonInfoEntity> implements PersonInfoService {

    @Override
    public List<PersonInfoEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.id");
        params.put("asc", false);
        Page<PersonInfoEntity> page = new QueryPlus<PersonInfoEntity>(params).getPage();
        return page.setRecords(baseMapper.selectPersonInfoPage(page, params));
    }

    @Override
    public boolean add(PersonInfoEntity personInfo) {
        return this.save(personInfo);
    }

    @Override
    public boolean update(PersonInfoEntity personInfo) {
        return this.updateById(personInfo);
    }

    @Override
    public boolean delete(Long id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(Long[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }


    @Override
    public boolean isExistsInfo(String idCardNo) {
        if (StringUtils.isEmpty(idCardNo)) {
            return true;
        }

        QueryWrapper<PersonInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(PersonInfoEntity.ID_CARD_NO, idCardNo);

        int count = this.count(queryWrapper);


        return count > 0;

    }
}
